package cn.crex1.xiaomi.dao.impl;

import java.util.List;

import cn.crex1.xiaomi.core.orm.annotion.Query;
import cn.crex1.xiaomi.core.orm.template.QueryTemplate;
import cn.crex1.xiaomi.core.orm.template.util.QueryUtils;
import cn.crex1.xiaomi.dao.CategorySDao;
import cn.crex1.xiaomi.dao.ProductDao;
import cn.crex1.xiaomi.pojo.Category;
import cn.crex1.xiaomi.pojo.Product;
import cn.crex1.xiaomi.pojo.SAttribute;
import cn.crex1.xiaomi.pojo.Specification;
import cn.crex1.xiaomi.vo.CategoryVO;
import cn.crex1.xiaomi.vo.ProductVO;

public class ProductDaoImpl implements ProductDao{

	@Override
	public int insertAllOsproduct(Product product) {
		QueryTemplate queryTemplate = QueryUtils.openTemplate();
		ProductDao productDao = queryTemplate.getmapper(ProductDao.class, new Object[] {product.getName(),product.getShow_price()});
		return productDao.insertAllOsproduct(product);
	}

	@Override
	public int deleteOsproductByProductid(Product product) {
		QueryTemplate queryTemplate = QueryUtils.openTemplate();
		ProductDao productDao = queryTemplate.getmapper(ProductDao.class,new Object[] { product.getProduct_id()});
		return productDao.deleteOsproductByProductid(product);
	}

	@Override
	public int updateOsproductByShowpriceAndName(Product product) {
		QueryTemplate queryTemplate = QueryUtils.openTemplate();
		ProductDao productDao = queryTemplate.getmapper(ProductDao.class,new Object[] { product.getName(),product.getShow_price(),product.getProduct_id()});
		return productDao.updateOsproductByShowpriceAndName(product);
	}
	
	@Override
	public List<Product> selectAllProduct(Product product) {
		QueryTemplate queryTemplate = QueryUtils.openTemplate();
		ProductDao productDao = queryTemplate.getmapper(ProductDao.class,new Object[] {} );
		return productDao.selectAllProduct(product);
	}
	
	@Override
	public List<Category> selectAllProductcategory(Category category) {
		QueryTemplate queryTemplate=QueryUtils.openTemplate();
		ProductDao productDao =queryTemplate.getmapper(ProductDao.class, new Object[] {category.getType()});
		return productDao.selectAllProductcategory(category);
	}

	@Override
	public List<Product> selectOsproductByDetails(Product product,SAttribute sAttribute,Specification specification) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();
		ProductDao productDao =queryTemplate.getmapper(ProductDao.class, new Object[] {product.getProduct_number()});
		return productDao.selectOsproductByDetails(product,sAttribute,specification);
	}
	@Override
	public List<ProductVO> selectOProductByOCategoryId(ProductVO productVO) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();

		ProductDao productDao=queryTemplate.getmapper(CategorySDao.class, new Object [] {productVO.getCategory_id()});
		
		return productDao.selectOProductByOCategoryId(productVO);
	}

	@Override
	public List<ProductVO> selectAllCategoryProduct(ProductVO productVO) {
		
		QueryTemplate queryTemplate =QueryUtils.openTemplate();
		
		ProductDao productDao=queryTemplate.getmapper(ProductDao.class, new Object [] {});
		
		return productDao.selectAllCategoryProduct(productVO);
	}
}
